from django.db import models
from datetime import datetime
from django.contrib.auth.models import User
from utility import getPath
import os
def get_image_path(instance, filename):
    return os.path.join('photos', str(instance.id), filename)
#def getPath(instance, filename):
  #  SETTINGS_DIR = os.path.dirname(__file__)
   # PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
    #PROJECT_PATH = os.path.abspath(PROJECT_PATH)
    #STATIC_PATH = os.path.join(PROJECT_PATH, 'static')
    #UploadDir=os.path.join(STATIC_PATH,'adminImages')
    #return os.path.join(UploadDir, str(instance.id), filename)
ROOM_CHOICES = (
    ('Double', 'Double'),
    ('Single', 'Single'),
    ('Wing', 'Wing'),
)
class Company(models.Model):
    Name=models.CharField(max_length=128,unique=True)
    Address=models.CharField(max_length=128)
    Contact=models.IntegerField(max_length=128)
    Image = models.ImageField(upload_to='media/')
    def __unicode__(self):
        return self.Name

class Hotel(models.Model):
    Name=models.CharField(max_length=128)
    Address=models.CharField(max_length=128)
    City=models.CharField(max_length=10)
    Country=models.CharField(max_length=128)
    Contact=models.IntegerField(max_length=40)
    HotelImage = models.ImageField(upload_to='media/')
    def __unicode__(self):
        return self.Name

class Room(models.Model):
    type=models.CharField(max_length=128)
    price=models.IntegerField(max_length=40)
    image = models.ImageField(upload_to='media/')
    hotel=models.ForeignKey(Hotel)


class Offer(models.Model):
    offer_discount=models.IntegerField(max_length=40)
    offer_start=models.DateField()
    offer_end=models.DateField()
    hotel=models.ForeignKey(Hotel)
    company=models.ForeignKey(Company)

class HotelRoomsInOffer(models.Model):
    offer=models.ForeignKey(Offer)
    room=models.ForeignKey(Room)


class UserBooking(models.Model):
    user=models.ForeignKey(User)
    startdate = models.DateField()
    enddate = models.DateField()
    offer = models.ForeignKey(Offer)

class HotelComment(models.Model):
    body = models.TextField(max_length=250)
    added = models.DateTimeField(auto_now_add=True)
    hotel = models.ForeignKey(Hotel)
    offer = models.ForeignKey(Offer)
    user = models.ForeignKey(User)

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    Address = models.CharField(max_length=128,blank=True)
    City = models.CharField(max_length=20)
    Mobile = models.IntegerField(max_length=15)

    def __unicode__(self):
        return self.user.username




